#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>

int main() {
    // 图像参数
    int width = 800, height = 600;
    cv::Scalar black_background(0, 0, 0); // 全黑背景

    // 创建空白图像
    cv::Mat image = cv::Mat::zeros(height, width, CV_8UC3);

    // --- 绘制直线 ---
    int line_thickness = 15; // 线条粗细
    cv::Scalar green(0, 255, 0), blue(255, 0, 0), red(0, 0, 255); // 定义颜色
    cv::Point line1_start(50, 50), line1_end(200, 50); // 直线1起点和终点
    cv::Point line2_start(50, 100), line2_end(250, 100); // 直线2起点和终点
    cv::Point line3_start(50, 150), line3_end(250, 150); // 直线3起点和终点

    cv::line(image, line1_start, line1_end, green, line_thickness, cv::LINE_8);
    cv::line(image, line2_start, line2_end, blue, line_thickness, cv::LINE_AA);
    cv::line(image, line3_start, line3_end, red, line_thickness, cv::LINE_4);

    // --- 绘制矩形 ---
    cv::Point rect_top_left(300, 100), rect_bottom_right(500, 300);
    cv::Scalar rect_color(255, 0, 0); // 蓝色
    int rect_thickness = 2; // 矩形边框厚度

    cv::rectangle(image, rect_top_left, rect_bottom_right, rect_color, rect_thickness);

    // --- 绘制圆形 ---
    cv::Point circle_center(400, 400);
    int circle_radius = 50;
    cv::Scalar circle_color(0, 0, 255); // 红色

    cv::circle(image, circle_center, circle_radius, circle_color, rect_thickness);

    // --- 绘制椭圆 ---
    cv::Point ellipse_center(600, 150);
    cv::Size ellipse_axes(100, 50);
    double ellipse_angle = 30.0, ellipse_start_angle = 0.0, ellipse_end_angle = 360.0;
    cv::Scalar ellipse_color(255, 255, 0); // 青色

    cv::ellipse(image, ellipse_center, ellipse_axes, ellipse_angle, ellipse_start_angle, ellipse_end_angle, ellipse_color, rect_thickness);

    // --- 绘制多边形 ---
    std::vector<cv::Point> polygon_points = {cv::Point(100, 500), cv::Point(200, 450), cv::Point(300, 500), cv::Point(250, 550), cv::Point(123, 456)};
    const cv::Point* polygon_data = polygon_points.data();
    int polygon_size = static_cast<int>(polygon_points.size());
    cv::Scalar polygon_color(255, 0, 255); // 紫色

    cv::polylines(image, &polygon_data, &polygon_size, 1, true, polygon_color, rect_thickness);

    // --- 添加文字 ---
    std::string text = "OpenCV Drawing Example";
    cv::Point text_org(50, 550); // 文本基线左下角起点
    double font_scale = 1.0;
    int text_thickness = 1;
    cv::Scalar text_color(255, 255, 255); // 白色

    cv::putText(image, text, text_org, cv::FONT_HERSHEY_SIMPLEX, font_scale, text_color, text_thickness, cv::LINE_AA);

    // --- 添加线条类型注释 ---
    cv::Scalar annotation_color(255, 255, 255); // 注释文字颜色
    cv::putText(image, "LINE_8", cv::Point(50, 40), cv::FONT_HERSHEY_SIMPLEX, 0.6, annotation_color, text_thickness);
    cv::putText(image, "LINE_AA", cv::Point(50, 90), cv::FONT_HERSHEY_SIMPLEX, 0.6, annotation_color, text_thickness);
    cv::putText(image, "LINE_4", cv::Point(50, 140), cv::FONT_HERSHEY_SIMPLEX, 0.6, annotation_color, text_thickness);

    // 显示图像
    cv::imshow("Drawing Example", image);
    cv::waitKey(0); // 等待用户按键

    // 保存图像到文件
    std::string output_filename = "drawing_example.png";
    cv::imwrite(output_filename, image);

    std::cout << "Drawing saved to " << output_filename << std::endl;

    return 0;
}
